<?php

Yii::import('common.models._base.BaseClassCourseTags');

class ClassCourseTags extends BaseClassCourseTags {

    public static function model($className = __CLASS__) {
        return parent::model($className);
    }

    public function rules() {
        return array(
            array('tag_name, create_time,status', 'required'),
            array('status', 'numerical', 'integerOnly' => true),
            array('tag_name', 'length', 'max' => 100),
            array('status', 'default', 'setOnEmpty' => true, 'value' => null),
            array('id, tag_name, status, create_time', 'safe', 'on' => 'search'),
        );
    }

    public static function getClassCourseTag($tagId) {
        $classTagCriteria = new CDbCriteria();
        $classTagCriteria->addInCondition('id', explode(',', $tagId));
        $classTagCriteria->addCondition('status=' . SkillConfig::STATUS_ACTIVE);
        return $classTag = ClassCourseTags::model()->findAll($classTagCriteria);
    }

    public function search() {
        $criteria = new CDbCriteria;
        $criteria->compare('id', $this->id, true);
        $criteria->compare('tag_name', $this->tag_name, true);
        $criteria->compare('status', $this->status);
        $criteria->compare('create_time', $this->create_time, true);
        $criteria->compare('users_id', $this->users_id);
        $criteria->order = 'create_time DESC';


        return new CActiveDataProvider($this, array(
                    'criteria' => $criteria,
                ));
    }

}